/****************************************************************************
** @brief human–computer interaction process
****************************************************************************/

#ifndef HCI_H
#define HCI_H

#include <QThread>

#include "baseUIData.h"
#include "baseConfigure.h"

class ChargeMain;

class HciMain : public QThread
{
    Q_OBJECT

public:
    ///
    /// \brief The HciPage enum
    ///
    enum HciPage {
        kHomePage = 0,     /* 主页 */
        kCardPage,         /* 刷卡 */
        kStartOrStopPage,  /* 启动中和停止中 */
        kFaultPage,        /* 故障（告警） */
        kChargingPage,     /* 充电中 */
        kFinishPage,       /* 充电结束 */
        kConfigPage,       /* 配置 */
        kUpdatePage,       /* 升级 */
    };

    HciMain(QList<ChargeMain *> *chargelist, QObject *parent = nullptr);
    ~HciMain();

    ///
    /// \brief current_gun
    /// \return
    ///
    int current_gun() const;
    ///
    /// \brief action_card
    /// \return
    ///
    bool action_card(void);
    ///
    /// \brief set_action_config
    /// \param data
    ///
    void set_action_config(bool data);

    //cmd
    static bool StartChargeService(quint8 gunno);
    static void SetStartChargeService(quint8 gunno);
    static void ClearStartChargeService(quint8 gunno);
    static bool StopChargeService(quint8 gunno);
    static void SetStopChargeService(quint8 gunno);
    static void ClearStopChargeService(quint8 gunno);

protected:
    void run() Q_DECL_OVERRIDE;

private:
    bool m_quit;
    unsigned long m_cycle;

    ///
    /// \brief chargeMainList_
    ///
    QList<ChargeMain *> *chargeMainList_ = nullptr;

    BaseConfigure baseConfigure_;
    BaseUIData baseUIData_;

    int current_gun_;    //用户当前触发的枪
    bool action_return_; //用户主动返回到HOME的标志 | true: 用户主动返回到了HOME页
    bool action_config_; //用户正在进行参数配置的标志 | true: 用户正在进行配置
    bool action_card_;   //用户可以进行刷卡的标志 | true: 用户可以刷卡

    //cmd - flag
    static QList<bool> start_charge_service_;
    static QList<bool> stop_charge_service_;

private:
    void Initialization();

    void ShowFaultInfo(int gunno);
    void ShowStopResultInfo(int gunno);
    void MakeQRcode(const QString& qrData, const QString& saveName);

signals:
    void ChangePage(const quint8& index);
    void ShowSysConfigData(const BaseUIData& uiData);
    void ShowSysCheckData(const BaseUIData& uiData);
    void UpdateData(const BaseUIData& uiData);
    void UpdateDateTime();

    void StartUpdate(qint32 version, qint32 subversion, qint32 revision, qint32 packLength, qint32 checkSum, QString updateAddress);

public slots:
    void HandleButton();
    void ShowConfigPage();

private slots:

};

#endif // HCI_H
